/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.h2;
 
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.mycompany.h2.H2ORMConn;
import com.mycompany.h2.StudentInfo;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.h2.tools.Server;

/**
 *
 * @author Administrator
 */
public class StudentDAO   {
    private Server server;
    private ConnectionSource conn;
    
    public StudentDAO(Server server){
        this.server=server;
        conn=   H2ORMConn.getConn(server);
    }
    
    public void createTable(StudentInfo info){
        try {
            TableUtils.createTableIfNotExists(conn, info.getClass());
                    } catch (SQLException ex) {
            Logger.getLogger(StudentDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public Dao<StudentInfo ,Integer>  getStudentDAO(){
        Dao<StudentInfo ,Integer> studentDAO=null;
        try {
            studentDAO = DaoManager.createDao(conn, StudentInfo.class);
        } catch (SQLException ex) {
            Logger.getLogger(StudentDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return studentDAO;
    }
    
    public void close(){
        H2ORMConn.closeCon(conn);
    }
}
